<?php

/* @var $this yii\web\View */

$this->title = '玩客快栈';
?>
<div class="site-index">
    <?php echo $this->render('/public/top'); ?>
    <div class="col-md-6">
        <ul class="nav">
            <?php if(Yii::$app->user->identity->wallet_addr == ''):?>
            <p class="lead">您还没有激活账户完成激活</p>
            <p>请往账户：
                <span style="font-size: 14px; color: green"><?php echo Yii::$app->params['walk_recharge']?></span>充值<br>
                <span style="font-size: 14px; color: red"><?=bcdiv(Yii::$app->user->identity->active_amount,1,3)?></span>wkc
                来完成激活
            </p>
            <p id="re-walter" style="display: none">
                充值需要稍等几分钟........
            </p>
            <p>
                <a class="btn btn-check-active" href="javascript:void(0)" role="button" data-toggle="modal">我已充值</a>
            </p>
            <p>
                充值成功后，系统将完成自动绑定，您也可以手动绑定钱包。完成充值
            </p>
            <p>
                <a class="btn" href="#bindWallet" role="button" data-toggle="modal">手动绑定</a>
            </p>
            <?php endif;?>
            <?php if(Yii::$app->user->identity->wallet_addr != '' && Yii::$app->user->identity->status == 0):?>
                <p class="lead">您还没有激活</p>
                <li>
                    <a class="btn btn-success" href="#showActive" role="button" data-toggle="modal">我要激活</a>
                </li>
            <?php endif?>
        </ul>
    </div>
    <div id="bindWallet" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">绑定钱包</h3>
        </div>
        <div class="modal-body">
            <p>
                <input type="text" placeholder="输入您的钱包地址" name="wallet_addr" id="wallet_addr" value="<?php if (!empty($userRow)) {echo $userRow['wallet_addr'];}?>">
                <input type="hidden" value="<?php echo \Yii::$app->getRequest()->getCsrfToken(); ?>" id="YII_CSRF_TOKEN2" name="YII_CSRF_TOKEN" />
            </p>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button class="btn btn-primary btn-build">确定</button>
        </div>
    </div>

    <div id="bindWalk" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">友情提醒</h3>
        </div>
        <div class="modal-body">
            <p>
                您还未充值
            </p>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('.btn-build').click(function(){
            var wallet_addr = $('#wallet_addr').val();
            if (wallet_addr == '') {
                alert('请输入钱包地址');
                return false;
            }
            if(wallet_addr.length < 15) {
                alert('钱包地址非法');
                return false;
            }
            var YII_CSRF_TOKEN2 = $('#YII_CSRF_TOKEN2').val();
            $.post('/user/build-wallet', {wallet_addr: wallet_addr, _csrf : YII_CSRF_TOKEN2}, function(data){
                alert(data.msg);
                if (data.code == 10000) {
                    location.reload();
                }
                return false;
            });
        });

        $('.btn-check-active').click(function(){
            var YII_CSRF_TOKEN2 = $('#YII_CSRF_TOKEN2').val();
            $.post('/user/check-active', {_csrf : YII_CSRF_TOKEN2}, function(data){
                if (data.code == 10000) {
                    alert('恭喜您充值成功');
                    location.href = '/user/index';
                } else {
                    $('#ts-walter').hide();
                    $('#re-walter').show();
                }
                return false;
            });
        });
    });
</script>